<?php
/**
 * @author: zhouzhongyuan <435690026@qq.com>
 */


namespace common\Utils;


use SoapClient;
use SoapFault;
use Yii;

class Webservice
{
    public static function get($url = [])
    {


    }

    public static function soap($url = [], $params = true, $getNames = null)
    {
        $url = Yii::$app->urlManager->createAbsoluteUrl($url);
        $hostInfo = Yii::$app->urlManager->getHostInfo();
        $url = str_replace($hostInfo, Yii::$app->params["webservice"], $url);
        try {
            $client = new SoapClient(null, [
                'location' => $url,
                'uri' => "soap"
            ]);
            if (is_array($params)) {
                foreach ($params as $name => $param) {
                    $client->__soapCall("set", [$name, $param]);
                }
                return $client->__soapCall("get", [$getNames]);
            }
            return $client;
        } catch (SoapFault $e) {
            throw $e;
        }
    }
}